package com.bw.common.base

import android.annotation.SuppressLint
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.fragment.app.Fragment
import com.blankj.utilcode.util.ToastUtils

/**
 * 基础的fragment(不具备架构模式的封装用于启动页之类)
 */
abstract class BaseFragment<VDB:ViewDataBinding>:Fragment() {
    lateinit var mDataBind:VDB

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
      mDataBind=DataBindingUtil.inflate(inflater,getLayoutId(),container,false)
        return mDataBind.root
    }

    //在view创建成功后初始化组件，否则可能组件加载不进来
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initView()
    }

    fun showToastMsg(msg:String){
        if (!msg.isNullOrEmpty()){
            ToastUtils.showLong(msg)
        }
    }

    abstract fun initView()

    abstract fun getLayoutId(): Int


}